<%-- 
    Document   : request_deposito
    Created on : 25/10/2011, 02:54:00 PM
    Author     : Jose
--%>

<%@ page import="PaquetesJL.*" %>
<%@page import="java.sql.ResultSet" %>

<%
    int tipo=Integer.parseInt(request.getParameter("tipo")); 
    
    String sqlServer = pageContext.getServletContext().getInitParameter("sqlServer");
    String databaseName = pageContext.getServletContext().getInitParameter("databaseName");
    String userName = pageContext.getServletContext().getInitParameter("userName");
    String PasswordP = pageContext.getServletContext().getInitParameter("password");
    String Backup = pageContext.getServletContext().getInitParameter("RutaBackup");
    
    byte[] decodedBytes = ConexionBD.decode(PasswordP);
    String decodedPassword = new String(decodedBytes).trim();
    
    ConexionBD Conexion = new ConexionBD(sqlServer, databaseName, userName, decodedPassword, Backup);
    if(tipo==0){   
        String cuenta=request.getParameter("id_cuenta");
        String aux=request.getParameter("monto");
        float monto=0;
        boolean exito=true;
        
        try{
            monto=Float.parseFloat(aux);
        }catch(Exception e){
            exito=false;
        }
        
        if(!exito || monto<=0){
            out.println("Debe ingresar un monto valido.");
        }else{
            Conexion.IniciarConexion();
            ResultSet r=Conexion.EjecutarConsulta("EXEC dbo.DepositoEfectivo "+cuenta+","+monto+",0");                           
            if(r.next()){        
                out.print(r.getString(1));
            } 
        }                      
    }else if(tipo==1){
        int id_emisor=Integer.parseInt(request.getParameter("id_emisor"));
        int id_receptor=Integer.parseInt(request.getParameter("id_receptor"));
        int id_cheque=Integer.parseInt(request.getParameter("id_cheque"));
        String montoaux=request.getParameter("monto");
        
        float monto=0;
        boolean exito=true;
        
        try{
            monto=Float.parseFloat(montoaux);
        }catch(Exception e){
            exito=false;
        }
        
        if(!exito || monto<=0){
            out.println("Debe ingresar un monto valido.");
        }else{
            Conexion.IniciarConexion();
            ResultSet r=Conexion.EjecutarConsulta("EXEC dbo.DepositoChequePropio "+id_emisor+","+id_receptor+","+id_cheque+","+monto+",0");                           
            if(r.next()){        
                out.print(r.getString(1));
            } 
        }
   }        
    
    
%>

